﻿<UserControl x:Class="MediaAssistant.Controls.MovieList.MovieListView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Behavior="clr-namespace:MefBasic.Behaviors;assembly=MefBasic"
             xmlns:Converters="clr-namespace:MediaAssistant.Converters" xmlns:MediaAssistant="clr-namespace:MediaAssistant">
  <UserControl.Resources>
    <Converters:NotNullVisibilityConverter x:Key="NotNullVisibilityConverter" />
    <MediaAssistant:MovieIndexConverter x:Key="MovieIndexConverter" />
  </UserControl.Resources>
  <DataGrid Name="Grid" HorizontalAlignment="Stretch"
       CanUserAddRows="False"
       CanUserDeleteRows="False"
       CanUserSortColumns="True"
       AutoGenerateColumns="False"
       AlternatingRowBackground="{StaticResource AlternatingRowBackground}"
       RowBackground="{StaticResource RowBackground}"
       HorizontalGridLinesBrush="{StaticResource GridLineBrush}"
       VerticalGridLinesBrush="{StaticResource GridLineBrush}"
       ItemsSource="{Binding DataSource.ResultMovies}"
       SelectionMode="Single"
       Behavior:SelectionBehavior.SelectionChanged="{Binding SelectedMovieChangedCommand}"
       VirtualizingStackPanel.IsVirtualizing="True"
       VirtualizingStackPanel.VirtualizationMode="Recycling"
       ScrollViewer.IsDeferredScrollingEnabled="True"
       EnableRowVirtualization="True"
          VerticalScrollBarVisibility="Auto"
          HorizontalScrollBarVisibility="Auto"
          >
    <DataGrid.ContextMenu>
      <ContextMenu>
        <MenuItem Header="Play" Command="{Binding DataSource.PlayMovieCommand}"/>
        <MenuItem Header="Alternative Locations" Command="{Binding DataSource.ShowAlternativeLocationsCommand}"/>
        <MenuItem Header="Mark as Pending" Command="{Binding DataSource.MarkeAsPendingCommand}"/>
        <MenuItem Header="Mark All Failed as Pending" Command="{Binding DataSource.MarkeAllFailedAsPendingCommand}"/>
        <Separator/>
        <MenuItem Header="Show in Windows Explorer" Command="{Binding DataSource.ShowMovieInWindowsExplorerCommand}"/>
      </ContextMenu>
    </DataGrid.ContextMenu>
    <DataGrid.Columns>
      <DataGridTemplateColumn Header="" Width="75" IsReadOnly="True">
        <DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
            <DockPanel>
              <ContentControl Width="16" Height="16" x:Name="iconWatched" Content="{StaticResource Eye16Image}" Opacity="0.3"/>
              <ContentControl Width="16" Height="16" x:Name="iconLocal" Content="{StaticResource Internet16Image}" Opacity="0.3"/>
              <TextBlock Name="textBlock" DockPanel.Dock="Left"
                         TextAlignment="Right" Width="30" Text="{Binding Index}">
                <TextBlock.Tag>
                  <MultiBinding Converter="{StaticResource MovieIndexConverter}">
                    <Binding/>
                    <Binding Path="Index"/>
                    <Binding RelativeSource="{RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGrid}}" Path="DataContext.DataSource"/>
                  </MultiBinding>
                </TextBlock.Tag>
              </TextBlock>
            </DockPanel>
            <DataTemplate.Triggers>
              <DataTrigger Binding="{Binding IsLocal}" Value="True">
                <Setter Property="Content" Value="{StaticResource NetworkStorage16Image}" TargetName="iconLocal"/>
                <Setter Property="Opacity" Value="1" TargetName="iconLocal"/>
              </DataTrigger>
              <DataTrigger Binding="{Binding Watched}" Value="True">
                <Setter Property="Opacity" Value="1" TargetName="iconWatched"/>
              </DataTrigger>
              <DataTrigger Binding="{Binding IsNew}" Value="True">
                <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
              </DataTrigger>
            </DataTemplate.Triggers>
          </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>

      <DataGridTemplateColumn Header="File Name" Width="160" IsReadOnly="True">
        <DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
            <TextBlock Name="textBlock"
                       Text="{Binding Path=FileName}"
                       ToolTip="{Binding Path=FullPath}"
                       FontWeight="Normal"/>
            <DataTemplate.Triggers>
              <DataTrigger Binding="{Binding IsNew}" Value="True">
                <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
              </DataTrigger>
            </DataTemplate.Triggers>
          </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>

      <DataGridTemplateColumn Header="Title" Width="200">
        <DataGridTemplateColumn.CellEditingTemplate>
          <DataTemplate>
            <TextBox Text="{Binding Title}"/>
          </DataTemplate>
        </DataGridTemplateColumn.CellEditingTemplate>
        <DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
            <TextBlock Name="textBlock" Text="{Binding Title}"/>
            <DataTemplate.Triggers>
              <DataTrigger Binding="{Binding IsNew}" Value="True">
                <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
              </DataTrigger>
            </DataTemplate.Triggers>
          </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>

      <DataGridTemplateColumn Header="Year" Width="50" IsReadOnly="True">
        <DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
            <TextBlock Name="textBlock" Text="{Binding Year}" TextAlignment="Right"/>
            <DataTemplate.Triggers>
              <DataTrigger Binding="{Binding IsNew}" Value="True">
                <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
              </DataTrigger>
            </DataTemplate.Triggers>
          </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>

      <DataGridTemplateColumn Header="Rated" Width="60" IsReadOnly="True">
        <DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
            <TextBlock Name="textBlock" Text="{Binding Rated}"/>
            <DataTemplate.Triggers>
              <DataTrigger Binding="{Binding IsNew}" Value="True">
                <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
              </DataTrigger>
            </DataTemplate.Triggers>
          </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>

      <DataGridTemplateColumn Header="Runtime" Width="80" IsReadOnly="True">
        <DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
            <TextBlock Name="textBlock" Text="{Binding Runtime}" TextAlignment="Right"/>
            <DataTemplate.Triggers>
              <DataTrigger Binding="{Binding IsNew}" Value="True">
                <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
              </DataTrigger>
            </DataTemplate.Triggers>
          </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>

      <DataGridTemplateColumn Header="Size" Width="80" IsReadOnly="True">
        <DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
            <TextBlock Name="textBlock" Text="{Binding SizeText}" TextAlignment="Right"/>
            <DataTemplate.Triggers>
              <DataTrigger Binding="{Binding IsNew}" Value="True">
                <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
              </DataTrigger>
            </DataTemplate.Triggers>
          </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>

      <DataGridTemplateColumn Header="Rating" Width="50" IsReadOnly="True">
        <DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
            <TextBlock Name="textBlock" Text="{Binding Rating}" TextAlignment="Right" />
            <DataTemplate.Triggers>
              <DataTrigger Binding="{Binding IsNew}" Value="True">
                <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
              </DataTrigger>
            </DataTemplate.Triggers>
          </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>
      
      <DataGridTemplateColumn Header="Votes" Width="80" IsReadOnly="True">
        <DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
            <TextBlock Name="textBlock" Text="{Binding Votes}" TextAlignment="Right" />
            <DataTemplate.Triggers>
              <DataTrigger Binding="{Binding IsNew}" Value="True">
                <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
              </DataTrigger>
            </DataTemplate.Triggers>
          </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>

      <DataGridTemplateColumn Header="Weighted Rating" Width="100" IsReadOnly="True">
        <DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
            <TextBlock Name="textBlock" Text="{Binding WeightedRating, StringFormat={}{0:F2}}" TextAlignment="Right" />
            <DataTemplate.Triggers>
              <DataTrigger Binding="{Binding IsNew}" Value="True">
                <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
              </DataTrigger>
            </DataTemplate.Triggers>
          </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>
      
      <DataGridTemplateColumn Header="IMDB" Width="80">
        <DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
            <Button Style="{StaticResource LinkButtonStyle}" ToolTip="Show movie in IMDB web site"
                    Visibility="{Binding IMDBId, Converter={StaticResource NotNullVisibilityConverter}}"
                    Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.DataSource.ShowMovieInIMDBCommand}">
              <Button.Content>
                <StackPanel Orientation="Horizontal">
                  <ContentControl Width="16" Height="16" Content="{StaticResource IMDBImage}" />
                  <TextBlock Text="IMDB" Margin="3"/>
                </StackPanel>
              </Button.Content>
            </Button>
          </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>
      <DataGridTemplateColumn Header="Status" Width="80" IsReadOnly="True">
        <DataGridTemplateColumn.CellTemplate>
          <DataTemplate>
            <TextBlock Name="textBlock" Text="{Binding Status}"/>
            <DataTemplate.Triggers>
              <DataTrigger Binding="{Binding IsNew}" Value="True">
                <Setter Property="FontWeight" Value="Bold" TargetName="textBlock"/>
              </DataTrigger>
            </DataTemplate.Triggers>
          </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>
    </DataGrid.Columns>
  </DataGrid>
</UserControl>